import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/',
            redirect: '/dashboard'
        },
        {
            path: '/',
            component: resolve => require(['../components/common/Home.vue'], resolve),
            meta: { title: '自述文件' },
            children:[
                {
                    path: '/dashboard',
                    component: resolve => require(['../views/sys/Dashboard.vue'], resolve),
                    meta: { title: '系统首页' }
                },
                {
                    path: '/hospitalMag',
                    component: resolve => require(['../views/sys/hospital/hospotalManage.vue'], resolve),
                    meta: { title: '医院管理'}
                },
                {
                    path: '/hospitalAdd',
                    component: resolve => require(['../views/sys/hospital/hospitalAdd.vue'], resolve),
                    meta: { title: '医院添加'}
                },
                {
                    path: '/userMag',
                    component: resolve => require(['../views/sys/userManage.vue'], resolve),
                    meta: { title: '用户管理'}
                },
                {
                    path: '/userExam',
                    component: resolve => require(['../views/sys/userExam.vue'], resolve),
                    meta: { title: '用户审核'}
                },
                {
                    path: '/serviceTypeManage',
                    component: resolve => require(['../views/sys/service/serviceTypeManage.vue'], resolve),
                    meta: { title: '服务分类管理'}
                },
                {
                    path: '/serviceManage',
                    component: resolve => require(['../views/sys/service/serviceManage.vue'], resolve),
                    meta: { title: '服务详情管理'}
                },
                {
                    path: '/addService',
                    component: resolve => require(['../views/sys/service/addService.vue'], resolve),
                    meta: { title: '服务添加'}
                },
                {
                    path: 'nurseMag',
                    component: resolve => require(['../views/sys/nurseManage.vue'], resolve),
                    meta: { title: '护士管理'}
                },
                {
                    path: 'financeManage',
                    component: resolve => require(['../views/sys/financeManage.vue'], resolve),
                    meta: { title: '财务管理'}
                },
                {
                    path: 'orderManage',
                    component: resolve => require(['../views/sys/orderManage.vue'], resolve),
                    meta: { title: '订单管理'}
                },
                {
                    path: 'appConfig',
                    component: resolve => require(['../views/sys/appConfig.vue'], resolve),
                    meta: { title: 'app配置'}
                },
                {
                    path: 'baseConfig',
                    component: resolve => require(['../views/sys/baseConfig.vue'], resolve),
                    meta: { title: '基础设置'}
                },
                {
                    path: 'map',
                    component: resolve => require(['../views/sys/map.vue'], resolve),
                    meta: { title: '地图调用'}
                },
                {
                    path: '/editor',
                    component: resolve => require(['../components/page/editor.vue'], resolve),
                    meta: { title: '富文本'}
                },

                {
                    path: '/404',
                    component: resolve => require(['../components/page/404.vue'], resolve),
                    meta: { title: '404' }
                },
                {
                    path: '/403',
                    component: resolve => require(['../components/page/403.vue'], resolve),
                    meta: { title: '403' }
                }
            ]
        },
        {
            path: '/login',
            component: resolve => require(['../views/sys/Login.vue'], resolve)
        },
        {
            path: '*',
            redirect: '/404'
        }
    ]
});
// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
    if (to.path === '/login') {
      next();
    } else {
      let token = sessionStorage.getItem('Authorization');
   
      if (token === 'null' || token === '') {
        next('/login');
      } else {
        next();
      }
    }
  });
  export default router;
